package org.ihelpuoo.weboo.action.http.util;

import java.util.ArrayList;
import java.util.List;

import org.ihelpuoo.util.Pager;
import org.ihelpuoo.util.Pair;
import org.ihelpuoo.weboo.action.http.AjaxListAction;
import org.ihelpuoo.weboo.module.ActionContext;

public class ConstantsAction extends AjaxListAction
{

	@Override
	protected List generateList(ActionContext context, Pager pager) throws Exception
	{
		String prefix = context.properties().getStringTrimed("prefix");
		String suffix = context.properties().getStringTrimed("suffix");
		int offset = context.properties().getInt("offset");
		int len = context.properties().getInt("length");

		List<Pair> list = new ArrayList<Pair>(len);
		for (int i = offset; i < len; i++)
		{
			Pair p = new Pair();
			p.setName(context.getMessage((prefix == null ? "" : prefix) + i
					+ (suffix == null ? "" : suffix)));
			p.setValue(String.valueOf(i));
			list.add(p);
		}

		return list;
	}
}
